using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VSYSBUTT
    {
        public DataRow Convert2SYSBUTT(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QuerySYSBUTT(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["SYBUMANDANT"] = " ".PadRight(2 ); 
         dwReturn["SYBUPROG"] = " ".PadRight(8 ); 
         dwReturn["SYBUUGRP"] = " ".PadRight(8 ); 
         dwReturn["SYBUSPRKZ"] = " ".PadRight(2 ); 
         dwReturn["SYBULFDNR"] = " ".PadRight(2 ); 
         dwReturn["SYBUAEND"] = " ".PadRight(0 ); 
         dwReturn["SYBUAENB"] = " ".PadRight(8 ); 
         dwReturn["SYBUNEUD"] = " ".PadRight(0 ); 
         dwReturn["SYBUNEUB"] = " ".PadRight(8 ); 
         dwReturn["SYBUAENZL"] = " ".PadRight(0 ); 
         dwReturn["SYBUBUTT01"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT02"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT03"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT04"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT05"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT06"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT07"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT08"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT09"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT10"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT11"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT12"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT13"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT14"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT15"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT16"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT17"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT18"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT19"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT20"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT21"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT22"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT23"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT24"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT25"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT26"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT27"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT28"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT29"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT30"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT31"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT32"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT33"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT34"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT35"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT36"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT37"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT38"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT39"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT40"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT41"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT42"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT43"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT44"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT45"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT46"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT47"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT48"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT49"] = " ".PadRight(115 ); 
         dwReturn["SYBUBUTT50"] = " ".PadRight(115 ); 
         dwReturn["SYBUFILLER"] = " ".PadRight(202 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapSYSBUTT(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveSYSBUTT(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QuerySYSBUTT(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapSYSBUTT(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertSYSBUTT(dwLocal, ITXDBVERSION);
            }
            UpdateSYSBUTT(dwLocal);
        }
        public void InsertSYSBUTT(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO SYSBUTT(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QuerySYSBUTT(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM SYSBUTT WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM SYSBUTT  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "SYSBUTT";
            Return = Result;
            return Return;
        }
        public void DeleteSYSBUTT(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM SYSBUTT   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateSYSBUTT(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE SYSBUTT SET "
                    +"SYBUMANDANT= :SYBUMANDANT,"
                    +"SYBUPROG= :SYBUPROG,"
                    +"SYBUUGRP= :SYBUUGRP,"
                    +"SYBUSPRKZ= :SYBUSPRKZ,"
                    +"SYBULFDNR= :SYBULFDNR,"
                    +"SYBUAEND= :SYBUAEND,"
                    +"SYBUAENB= :SYBUAENB,"
                    +"SYBUNEUD= :SYBUNEUD,"
                    +"SYBUNEUB= :SYBUNEUB,"
                    +"SYBUAENZL= :SYBUAENZL,"
                    +"SYBUBUTT01= :SYBUBUTT01,"
                    +"SYBUBUTT02= :SYBUBUTT02,"
                    +"SYBUBUTT03= :SYBUBUTT03,"
                    +"SYBUBUTT04= :SYBUBUTT04,"
                    +"SYBUBUTT05= :SYBUBUTT05,"
                    +"SYBUBUTT06= :SYBUBUTT06,"
                    +"SYBUBUTT07= :SYBUBUTT07,"
                    +"SYBUBUTT08= :SYBUBUTT08,"
                    +"SYBUBUTT09= :SYBUBUTT09,"
                    +"SYBUBUTT10= :SYBUBUTT10,"
                    +"SYBUBUTT11= :SYBUBUTT11,"
                    +"SYBUBUTT12= :SYBUBUTT12,"
                    +"SYBUBUTT13= :SYBUBUTT13,"
                    +"SYBUBUTT14= :SYBUBUTT14,"
                    +"SYBUBUTT15= :SYBUBUTT15,"
                    +"SYBUBUTT16= :SYBUBUTT16,"
                    +"SYBUBUTT17= :SYBUBUTT17,"
                    +"SYBUBUTT18= :SYBUBUTT18,"
                    +"SYBUBUTT19= :SYBUBUTT19,"
                    +"SYBUBUTT20= :SYBUBUTT20,"
                    +"SYBUBUTT21= :SYBUBUTT21,"
                    +"SYBUBUTT22= :SYBUBUTT22,"
                    +"SYBUBUTT23= :SYBUBUTT23,"
                    +"SYBUBUTT24= :SYBUBUTT24,"
                    +"SYBUBUTT25= :SYBUBUTT25,"
                    +"SYBUBUTT26= :SYBUBUTT26,"
                    +"SYBUBUTT27= :SYBUBUTT27,"
                    +"SYBUBUTT28= :SYBUBUTT28,"
                    +"SYBUBUTT29= :SYBUBUTT29,"
                    +"SYBUBUTT30= :SYBUBUTT30,"
                    +"SYBUBUTT31= :SYBUBUTT31,"
                    +"SYBUBUTT32= :SYBUBUTT32,"
                    +"SYBUBUTT33= :SYBUBUTT33,"
                    +"SYBUBUTT34= :SYBUBUTT34,"
                    +"SYBUBUTT35= :SYBUBUTT35,"
                    +"SYBUBUTT36= :SYBUBUTT36,"
                    +"SYBUBUTT37= :SYBUBUTT37,"
                    +"SYBUBUTT38= :SYBUBUTT38,"
                    +"SYBUBUTT39= :SYBUBUTT39,"
                    +"SYBUBUTT40= :SYBUBUTT40,"
                    +"SYBUBUTT41= :SYBUBUTT41,"
                    +"SYBUBUTT42= :SYBUBUTT42,"
                    +"SYBUBUTT43= :SYBUBUTT43,"
                    +"SYBUBUTT44= :SYBUBUTT44,"
                    +"SYBUBUTT45= :SYBUBUTT45,"
                    +"SYBUBUTT46= :SYBUBUTT46,"
                    +"SYBUBUTT47= :SYBUBUTT47,"
                    +"SYBUBUTT48= :SYBUBUTT48,"
                    +"SYBUBUTT49= :SYBUBUTT49,"
                    +"SYBUBUTT50= :SYBUBUTT50,"
                    +"SYBUFILLER= :SYBUFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("SYBUMANDANT", OracleType.NVarChar).Value = dwData["SYBUMANDANT"].ToString(); 
          or1.Parameters.Add("SYBUPROG", OracleType.NVarChar).Value = dwData["SYBUPROG"].ToString(); 
          or1.Parameters.Add("SYBUUGRP", OracleType.NVarChar).Value = dwData["SYBUUGRP"].ToString(); 
          or1.Parameters.Add("SYBUSPRKZ", OracleType.NVarChar).Value = dwData["SYBUSPRKZ"].ToString(); 
          or1.Parameters.Add("SYBULFDNR", OracleType.NVarChar).Value = dwData["SYBULFDNR"].ToString(); 
          or1.Parameters.Add("SYBUAEND", OracleType.NVarChar).Value = dwData["SYBUAEND"].ToString(); 
          or1.Parameters.Add("SYBUAENB", OracleType.NVarChar).Value = dwData["SYBUAENB"].ToString(); 
          or1.Parameters.Add("SYBUNEUD", OracleType.NVarChar).Value = dwData["SYBUNEUD"].ToString(); 
          or1.Parameters.Add("SYBUNEUB", OracleType.NVarChar).Value = dwData["SYBUNEUB"].ToString(); 
          or1.Parameters.Add("SYBUAENZL", OracleType.NVarChar).Value = dwData["SYBUAENZL"].ToString(); 
          or1.Parameters.Add("SYBUBUTT01", OracleType.NVarChar).Value = dwData["SYBUBUTT01"].ToString(); 
          or1.Parameters.Add("SYBUBUTT02", OracleType.NVarChar).Value = dwData["SYBUBUTT02"].ToString(); 
          or1.Parameters.Add("SYBUBUTT03", OracleType.NVarChar).Value = dwData["SYBUBUTT03"].ToString(); 
          or1.Parameters.Add("SYBUBUTT04", OracleType.NVarChar).Value = dwData["SYBUBUTT04"].ToString(); 
          or1.Parameters.Add("SYBUBUTT05", OracleType.NVarChar).Value = dwData["SYBUBUTT05"].ToString(); 
          or1.Parameters.Add("SYBUBUTT06", OracleType.NVarChar).Value = dwData["SYBUBUTT06"].ToString(); 
          or1.Parameters.Add("SYBUBUTT07", OracleType.NVarChar).Value = dwData["SYBUBUTT07"].ToString(); 
          or1.Parameters.Add("SYBUBUTT08", OracleType.NVarChar).Value = dwData["SYBUBUTT08"].ToString(); 
          or1.Parameters.Add("SYBUBUTT09", OracleType.NVarChar).Value = dwData["SYBUBUTT09"].ToString(); 
          or1.Parameters.Add("SYBUBUTT10", OracleType.NVarChar).Value = dwData["SYBUBUTT10"].ToString(); 
          or1.Parameters.Add("SYBUBUTT11", OracleType.NVarChar).Value = dwData["SYBUBUTT11"].ToString(); 
          or1.Parameters.Add("SYBUBUTT12", OracleType.NVarChar).Value = dwData["SYBUBUTT12"].ToString(); 
          or1.Parameters.Add("SYBUBUTT13", OracleType.NVarChar).Value = dwData["SYBUBUTT13"].ToString(); 
          or1.Parameters.Add("SYBUBUTT14", OracleType.NVarChar).Value = dwData["SYBUBUTT14"].ToString(); 
          or1.Parameters.Add("SYBUBUTT15", OracleType.NVarChar).Value = dwData["SYBUBUTT15"].ToString(); 
          or1.Parameters.Add("SYBUBUTT16", OracleType.NVarChar).Value = dwData["SYBUBUTT16"].ToString(); 
          or1.Parameters.Add("SYBUBUTT17", OracleType.NVarChar).Value = dwData["SYBUBUTT17"].ToString(); 
          or1.Parameters.Add("SYBUBUTT18", OracleType.NVarChar).Value = dwData["SYBUBUTT18"].ToString(); 
          or1.Parameters.Add("SYBUBUTT19", OracleType.NVarChar).Value = dwData["SYBUBUTT19"].ToString(); 
          or1.Parameters.Add("SYBUBUTT20", OracleType.NVarChar).Value = dwData["SYBUBUTT20"].ToString(); 
          or1.Parameters.Add("SYBUBUTT21", OracleType.NVarChar).Value = dwData["SYBUBUTT21"].ToString(); 
          or1.Parameters.Add("SYBUBUTT22", OracleType.NVarChar).Value = dwData["SYBUBUTT22"].ToString(); 
          or1.Parameters.Add("SYBUBUTT23", OracleType.NVarChar).Value = dwData["SYBUBUTT23"].ToString(); 
          or1.Parameters.Add("SYBUBUTT24", OracleType.NVarChar).Value = dwData["SYBUBUTT24"].ToString(); 
          or1.Parameters.Add("SYBUBUTT25", OracleType.NVarChar).Value = dwData["SYBUBUTT25"].ToString(); 
          or1.Parameters.Add("SYBUBUTT26", OracleType.NVarChar).Value = dwData["SYBUBUTT26"].ToString(); 
          or1.Parameters.Add("SYBUBUTT27", OracleType.NVarChar).Value = dwData["SYBUBUTT27"].ToString(); 
          or1.Parameters.Add("SYBUBUTT28", OracleType.NVarChar).Value = dwData["SYBUBUTT28"].ToString(); 
          or1.Parameters.Add("SYBUBUTT29", OracleType.NVarChar).Value = dwData["SYBUBUTT29"].ToString(); 
          or1.Parameters.Add("SYBUBUTT30", OracleType.NVarChar).Value = dwData["SYBUBUTT30"].ToString(); 
          or1.Parameters.Add("SYBUBUTT31", OracleType.NVarChar).Value = dwData["SYBUBUTT31"].ToString(); 
          or1.Parameters.Add("SYBUBUTT32", OracleType.NVarChar).Value = dwData["SYBUBUTT32"].ToString(); 
          or1.Parameters.Add("SYBUBUTT33", OracleType.NVarChar).Value = dwData["SYBUBUTT33"].ToString(); 
          or1.Parameters.Add("SYBUBUTT34", OracleType.NVarChar).Value = dwData["SYBUBUTT34"].ToString(); 
          or1.Parameters.Add("SYBUBUTT35", OracleType.NVarChar).Value = dwData["SYBUBUTT35"].ToString(); 
          or1.Parameters.Add("SYBUBUTT36", OracleType.NVarChar).Value = dwData["SYBUBUTT36"].ToString(); 
          or1.Parameters.Add("SYBUBUTT37", OracleType.NVarChar).Value = dwData["SYBUBUTT37"].ToString(); 
          or1.Parameters.Add("SYBUBUTT38", OracleType.NVarChar).Value = dwData["SYBUBUTT38"].ToString(); 
          or1.Parameters.Add("SYBUBUTT39", OracleType.NVarChar).Value = dwData["SYBUBUTT39"].ToString(); 
          or1.Parameters.Add("SYBUBUTT40", OracleType.NVarChar).Value = dwData["SYBUBUTT40"].ToString(); 
          or1.Parameters.Add("SYBUBUTT41", OracleType.NVarChar).Value = dwData["SYBUBUTT41"].ToString(); 
          or1.Parameters.Add("SYBUBUTT42", OracleType.NVarChar).Value = dwData["SYBUBUTT42"].ToString(); 
          or1.Parameters.Add("SYBUBUTT43", OracleType.NVarChar).Value = dwData["SYBUBUTT43"].ToString(); 
          or1.Parameters.Add("SYBUBUTT44", OracleType.NVarChar).Value = dwData["SYBUBUTT44"].ToString(); 
          or1.Parameters.Add("SYBUBUTT45", OracleType.NVarChar).Value = dwData["SYBUBUTT45"].ToString(); 
          or1.Parameters.Add("SYBUBUTT46", OracleType.NVarChar).Value = dwData["SYBUBUTT46"].ToString(); 
          or1.Parameters.Add("SYBUBUTT47", OracleType.NVarChar).Value = dwData["SYBUBUTT47"].ToString(); 
          or1.Parameters.Add("SYBUBUTT48", OracleType.NVarChar).Value = dwData["SYBUBUTT48"].ToString(); 
          or1.Parameters.Add("SYBUBUTT49", OracleType.NVarChar).Value = dwData["SYBUBUTT49"].ToString(); 
          or1.Parameters.Add("SYBUBUTT50", OracleType.NVarChar).Value = dwData["SYBUBUTT50"].ToString(); 
          or1.Parameters.Add("SYBUFILLER", OracleType.NVarChar).Value = dwData["SYBUFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
